/**
 * Copyright &copy; 2013-2018 青岛数码人网络科技有限公司   All rights reserved.
 */
package cn.net.ecode.elec.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.net.ecode.common.config.Global;
import cn.net.ecode.common.persistence.Page;
import cn.net.ecode.common.web.BaseController;
import cn.net.ecode.common.utils.StringUtils;
import cn.net.ecode.elec.entity.ElecAgencyBtype;
import cn.net.ecode.elec.service.ElecAgencyBtypeService;

/**
 * 代理企业Controller
 * @author xiaodunshan
 * @version 2019-09-28
 */
@Controller
@RequestMapping(value = "${adminPath}/elec/elecAgencyBtype")
public class ElecAgencyBtypeController extends BaseController {

	@Autowired
	private ElecAgencyBtypeService elecAgencyBtypeService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ElecAgencyBtype get(String id, boolean isNewRecord) {
		return elecAgencyBtypeService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("elec:elecAgencyBtype:view")
	@RequestMapping(value = {"list", ""})
	public String list(ElecAgencyBtype elecAgencyBtype, Model model) {
		model.addAttribute("elecAgencyBtype", elecAgencyBtype);
		return "ecode/elec/elecAgencyBtypeList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("elec:elecAgencyBtype:view")
	@ResponseBody
	@RequestMapping(value = "listData")
	public Page<ElecAgencyBtype> listData(ElecAgencyBtype elecAgencyBtype, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ElecAgencyBtype> page = elecAgencyBtypeService.findPage(new Page<ElecAgencyBtype>(request, response), elecAgencyBtype); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("elec:elecAgencyBtype:view")
	@RequestMapping(value = "form")
	public String form(ElecAgencyBtype elecAgencyBtype, Model model) {
		model.addAttribute("elecAgencyBtype", elecAgencyBtype);
		return "ecode/elec/elecAgencyBtypeForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("elec:elecAgencyBtype:edit")
	@ResponseBody
	@RequestMapping(value = "save")
	public String save(ElecAgencyBtype elecAgencyBtype) {
		StringBuilder message = new StringBuilder();
		if (!beanValidator(message, elecAgencyBtype)){
			return renderResult(Global.FALSE, message);
		}
		elecAgencyBtypeService.save(elecAgencyBtype);
		return renderResult(Global.TRUE, "保存代理企业成功！");
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("elec:elecAgencyBtype:edit")
	@ResponseBody
	@RequestMapping(value = "delete")
	public String delete(ElecAgencyBtype elecAgencyBtype) {
		elecAgencyBtypeService.delete(elecAgencyBtype);
		return renderResult(Global.TRUE, "删除代理企业成功！");
	}

}